/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plagiadetector.driver;

import java.util.Iterator;
import java.util.Map.Entry;
import plagiadetector.datatype.GramCounter;
import plagiadetector.datatype.PANCorpus;
import plagiadetector.detector.OberDetector;
import plagiadetector.utility.PANXMLParser;


/**
 *
 * @author Dell
 */
public class OberDetectorDriver {
    public static void main(String[] args){
        OberDetector od = new OberDetector();
        String xmladdr = "corpusexamples\\PAN2011\\suspicious-document00016.xml";
        
        System.out.println("SETTING XML");
        PANCorpus panc = PANXMLParser.parseXML(xmladdr);
        
        System.out.println("SETTING RAW TEXT");
//        od.setRawText("There was great consternation in Fairyland, for it was suddenly discovered that the sun had\n"+
//"been shining crookedly all the morning.  It was consequently two hours later than anybody thought");        
//        od.setWindowSize(5);
        
        od.setRawText(panc.getCorpusText());
       
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("RAW TEXT, LENGTH : "+od.getRawText().length());
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println(od.getRawText());
        
        od.doPreprocessing();
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("PREPROCESSED TEXT, LENGTH"+od.getPreprocessedText().length());
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println(od.getPreprocessedText());
    
        od.doSegmentation();
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("GENERATED SEGMENTS");
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        for(int i = 0; i < od.getNumOfTextSegments() ; i++){
            System.out.println("################################################");
            System.out.println("SEGMENT NUMBER "+i+", OFFSET : "+od.getTextSegment(i).offset+", LENGTH : "+od.getTextSegment(i).segmentText.length());
            System.out.println("################################################");
            System.out.println(od.getTextSegment(i).segmentText);
        }
        
        od.doStylometricExtraction();
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("EXTRACTED FEATURES");
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println("################################################");
        System.out.println("WHOLE DOCUMENT FEATURES, NUMBER OF GRAMS : "+od.docgrams.size());
        System.out.println("################################################");

        for(String s : od.docgrams){
            System.out.println(s);
        }

        
        for(int i = 0; i < od.windowgrams.size(); i++){
             System.out.println("################################################");
             System.out.println("SEGMENT NUMBER "+i+" FEATURES, NUMBER OF GRAMS : "+od.windowgrams.get(i).size());
             System.out.println("################################################");

             for(String s : od.windowgrams.get(i)){
                 System.out.println(s);
             }
        }
        
        od.doStylometricQA();
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("QUANTIFIED FEATURES");
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println("################################################");
        System.out.println("WHOLE DOCUMENT QUANTIFIED FEATURES, NUMBER OF UNIQUE FEATURES : "+od.docgramfrequency.size());
        System.out.println("################################################");
  
        Iterator itx = od.docgramfrequency.entrySet().iterator();
        GramCounter gc;
        
        while(itx.hasNext()){
            gc = (GramCounter)((Entry)itx.next()).getValue();
            System.out.println("Gram : "+gc.text+", Freq : "+gc.occurrence);
        }
        
        for(int i = 0; i < od.windowgramfrequency.size(); i++){
             System.out.println("################################################");
             System.out.println("SEGMENT NUMBER "+i+" QUANTIFIED FEATURES, NUMBER OF UNIQUE FEATURES : "+od.windowgramfrequency.get(i).size());
             System.out.println("################################################");
             itx = od.windowgramfrequency.get(i).entrySet().iterator();
             while(itx.hasNext()){
                 gc = (GramCounter)((Entry)itx.next()).getValue();
                 System.out.println("Gram : "+gc.text+", Freq : "+gc.occurrence);
             
             }
        }
        
        System.out.println("################################################");
        System.out.println("WINDOW STYLES");
        System.out.println("################################################");
  
        for(int i = 0; i < od.windowstyle.size(); i++){
            System.out.println("Window number : "+i+" style change : "+od.windowstyle.get(i));            
        }
                
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("ANALYSIS - DETECTED CASES");
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        for(int i = 0; i < od.getNumOfCases(); i++){
            System.out.println("Case Number : "+i+" Offset : "+od.getCase(i).offset+" Length : "+od.getCase(i).length);
        }
    }
}
